package shaka.core.test

import shaka.core.DefShakaMethods
import shaka.core.internal.PkgFileReaderImpl
import shaka.core.params.DateDiff

DefShakaMethods.initialize()

class Arg1 {
	int k1
	int k2
	String k3
}
def test1 = { settings ->
	def args = new Arg1(
			k1:100,
			k2:200,
			k3:null)
	args << settings

	//println args.getProperties()
	List<PropertyValue> metaProps = args.getMetaPropertyValues()
	for(PropertyValue pv : metaProps){
		if(pv.name == 'class')
			continue
		println "name : [${pv.name}] , type : [${pv.type}] , value : [${pv.value}]"
	}

	println args as Map

	//println prop(args, 'k3', 'VVV')
	//println args?.prop('k1', 5)
}

def test2 = {
	Date now = 'yyyy-MM-dd HH:mm:ss'.dateParse('2011-10-11 12:30:50')
	// key - {@link shaka.core.face.DateDiff}
	Date nextYear = now + dateDiff(year : 1)
	Date prevYear = now - dateDiff(year : 1)
	DateDiff diff = nextYear - prevYear

	println 'yyyy-MM-dd HH:mm:ss'.dateFormat(nextYear) // 2012-10-11 12:30:50
	println 'yyyy-MM-dd HH:mm:ss'.dateFormat(prevYear) // 2010-10-11 12:30:50
	println diff as Map // [month:0, day:0, sec:0, hour:0, min:0, year:2]

	//println now.year
}

def test3 = {
	PkgFileReaderImpl pkg = new PkgFileReaderImpl('UTF-8')
	pkg.findProperties('shaka.core').each { pName -> println pName }
	pkg.findClasses('shaka.core', false) {error,className ->
		println error
		println className
	}.each { clazz -> println clazz }
}

def test4 = {
	// ...
	def s = [1, 2, 3]
	println s.join('-')

	println isEmpty(null)
	println isEmpty('')
	println isEmpty([])
	println isEmpty([1, 2, 3])
	println isEmpty([:])
	println isEmpty([k1:100,k2:200])

	println '=========='

	println prop(s, 2)
	println prop([k1:100,k2:200],'k2')
	println prop([k1:100,k2:200],'k3')
	println prop([k1:100,k2:200],'k3',300)
	println prop(null,'k3',300)
	println prop([100, 200, 300],0,999)
	println prop([],2,999)

	//	println '=========='
	//
	//	def obj1 = [s1:' abc ', s2:'abc']
	//	println prop(obj:obj1, propName:'s1')
	//	println prop(obj:obj1, propName:'s1', trimEmpty:false)
	//
	//	def arg1 = new Arg1(k1:1, k3:'  ccc  ')
	//	println prop(obj:arg1, propName:'k1')
	//	println prop(obj:arg1, propName:'k2', defValue:100)
	//	println prop(obj:arg1, propName:'k3')

	//	println ''.isEmpty()
	//	println ''.isNotEmpty()
	//	println 0.isEmpty()
	//	println 100.isEmpty()
	//	println([1,2,3].isEmpty())
	//	println([:].isEmpty())

}

class A {
	int x
	String y
	def z
	public String s1(){
		return '999'
	}

	public int s2(int i=100, int j=200){
		return i + j
	}
}

def test5 = {
	//MetaMethod s1 = A.metaClass.getMetaMethod("s1")
	//println s1.getReturnType()
	//println s1.getParameterTypes()

	//MetaMethod s2 = A.metaClass.getMetaMethod("s2", [int.class, int.class] as Class[])
	//println s2.getReturnType()
	//println s2.getParameterTypes()

	A a = new A(x:1,y:'str999')
	//println s1.invoke(a)
	//Closure c = a.&s2
	//println c.getParameterTypes()

	//	MetaProperty x = A.metaClass.getMetaProperty('x')
	//	println x.getType()
	//
	//	MetaProperty y = A.metaClass.getMetaProperty('y')
	//	println y.getType()
	//
	//	MetaProperty z = A.metaClass.getMetaProperty('z')
	//	println z.getType()
	//println prop(obj: a, propName: 'x')
	//println prop(obj: a, propName: 'y')
	prop(obj:javaBean, propName:'propName', defValue:100, isStr:true, trimEmpty:true)
	//println a.s2(i:1)
}

//test1(k1:1)
//test2()
//test3()
//test4()
test5()


